package org.chengn.level_middle.context2735;

/**
 * @Title: Context2735
 * @Author ChengN
 * @Package org.chengn.level_middle.context2735
 * @Date 2023/12/28 11:36
 * @description 收集巧克力
 */
public class Context2735 {
    public long minCost(int[] nums, int x) {
        int n = nums.length;
        long sum = 0x3f3f3f3f3f3f3f3fL;
        int[] dp = new int[n];
        System.arraycopy(nums, 0, dp, 0, n);
        for (int i = 0; i < n; ++i) {
            long thisSum = 0L;
            for (int j = 0; j < n; ++j) {
                int idx = (j + i) % n;
                dp[j] = Math.min(dp[j], nums[idx]);
                thisSum += (long)dp[j];
            }
            sum = Math.min(sum, thisSum + (long)i * x);

        }
        return sum;

    }
}
